/*
Dominique Jannone
Guillaume Marre
Yohan Ojeda
Laurent Schiavon
*/
package controleur;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import model.eConf;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

import Econf_Audio.Receveur_client;

import vue.Fenetre;
import java.util.logging.Logger;
import java.util.logging.Level;

public class afficheBodyGraphSupervision extends JPanel {

	
	private eConf eConf;
	private ChartPanel panel1;
	private ChartPanel panel2;
	private ChartPanel panel3;
	private ChartPanel panel4;
	private ChartPanel panel6;
	private ChartPanel panel7;
	private ChartPanel panel8;
	private JButton panel9;
	
	// Create a set of charts
	private JFreeChart chart1;
	private  JFreeChart chart2;
	private JFreeChart chart3;
	private JFreeChart chart4;
//	private JFreeChart chart5;
	private JFreeChart chart6;
	private JFreeChart chart7;
	private JFreeChart chart8;
	private JFreeChart chart9;
	
	//log
	public static final Logger logger = Logger.getLogger(afficheBodyGraphSupervision.class.getName());
	
	public afficheBodyGraphSupervision(eConf econf){
        eConf = econf;
	}

	afficheBodyGraphSupervision(){
		logger.log(Level.INFO,"afficheBodyGraphSupervision > methode");

		
	Object[][] tabInfoMonit = Fenetre.getTabInfoMonitoring();
	
	// Holds the data
	  DefaultPieDataset dataset = new DefaultPieDataset();
	  DefaultPieDataset dataset1 = new DefaultPieDataset();
	  DefaultPieDataset dataset2 = new DefaultPieDataset();
	  DefaultPieDataset dataset3 = new DefaultPieDataset();
//	  CategoryDataset dataset4 = DatasetUtilities.createCategoryDataset("S","C", data);
	  DefaultCategoryDataset dataset5 = new DefaultCategoryDataset();
	  DefaultCategoryDataset dataset6 = new DefaultCategoryDataset();
	  DefaultCategoryDataset dataset7 = new DefaultCategoryDataset();
	  DefaultCategoryDataset dataset8 = new DefaultCategoryDataset();


//Vérification que la base est up
//	  Number ConnexionBDDOK = null;
//	  Number ConnexionBDDNOK = null;
//	  if (tabInfoMonit[17][1] != null) {
//		 ConnexionBDDOK = 1;
//	  }
//	  else {
//		  ConnexionBDDNOK = 1;
//	  }
		  

// Initialize the dataset
		
		dataset.setValue("MemoireRAMLibre",(Number) tabInfoMonit[2][1]);
	    dataset.setValue("MemoireRAMUtilisee",(Number) tabInfoMonit[1][1]);
	    
	    dataset1.setValue("MemoireSWAPLibre",(Number) tabInfoMonit[5][1]);
	    dataset1.setValue("MemoireSWAPUtilisee",(Number) tabInfoMonit[4][1]);
	    
	    dataset2.setValue("Charge CPU Serveur Libre",(Number) tabInfoMonit[8][1]);
	    dataset2.setValue("Charge CPU Serveur Occupée",(Number) tabInfoMonit[7][1]);
	    
	    dataset3.setValue("EspaceDisqueDurUtilisé",(Number) tabInfoMonit[13][1]);
	    dataset3.setValue("EspaceDisqueLibre",(Number) tabInfoMonit[14][1]);
	    
	    dataset5.setValue((Number) tabInfoMonit[15][1], "Nb Conf privées Créée", "Créée");
	    dataset5.setValue((Number) tabInfoMonit[16][1], "Nb Conf privées en cours", "En cours");
	    dataset5.setValue((Number) tabInfoMonit[17][1], "Nb Conf privées terminée", "Terminée");
	    
	    dataset6.setValue((Number) tabInfoMonit[21][1], "Utilisateurs inscrits", "Users inscrits");
	    dataset6.setValue((Number) tabInfoMonit[22][1], "Utilisateurs non inscrits", "Users non inscrits");
	    dataset6.setValue(null, "         ", "             ");
	    
	    dataset7.setValue((Number) tabInfoMonit[18][1], "Nb Conf publiques Créée", "Créée");
	    dataset7.setValue((Number) tabInfoMonit[19][1], "Nb Conf publiques en cours", "En cours");
	    dataset7.setValue((Number) tabInfoMonit[20][1], "Nb Conf publiques terminée", "Terminée");
	    
//		dataset8.setValue(ConnexionBDDOK, "Etat de la connexion Serveur - BDD ok", "OK sur la BDD");
//		dataset8.setValue(ConnexionBDDNOK, "Etat de la connexion Serveur - BDD ok", "NOK sur la BDD");

	 // Create the charts
	 chart1 = ChartFactory.createPieChart3D(
	   "Memoire RAM", // The chart title
	   dataset,         // The dataset for the chart
	   true,          // Is a legend required?
	   true,          // Use tooltips
	   false          // Configure chart to generate URLs?
	 );
	 
	 chart2 = ChartFactory.createPieChart3D(
	   "Memoire SWAP", // The chart title
	   dataset1,         // The dataset for the chart
	   true,          // Is a legend required?
	   true,          // Use tooltips
	   false          // Configure chart to generate URLs?
	 );

	 chart3 = ChartFactory.createPieChart3D(
	   "CPU", // The chart title
	   dataset2,         // The dataset for the chart
	   true,          // Is a legend required?
	   true,          // Use tooltips
	   false          // Configure chart to generate URLs?
	 );
	 
	 chart4 = ChartFactory.createPieChart3D(
	   "Espace Disque", // The chart title
	   dataset3,         // The dataset for the chart
	   true,          // Is a legend required?
	   true,          // Use tooltips
	   false          // Configure chart to generate URLs?
	 );

	
//	 chart5 = ChartFactory.createLineChart("Network", 
//			 "Network", 
//			 "kps", 
//			 dataset4, 
//			 PlotOrientation.VERTICAL, 
//			 true, 
//			 true, 
//			 false);
	 
	 chart6 = ChartFactory.createBarChart3D("Nb Conf privée", 
			 "Conferenceprivée", 
			 "nb conf", 
			 dataset5, 
			 PlotOrientation.HORIZONTAL, 
			 true, 
			 true, 
			 false);
	 
	 
	 chart7 = ChartFactory.createBarChart3D("Utilisateurs", 
			 "Utilisateurs inscrits", 
			 "Utilisateurs non inscrits", 
			 dataset6, 
			 PlotOrientation.HORIZONTAL, 
			 true, 
			 true, 
			 false);
	 
	 
	 chart8 = ChartFactory.createBarChart3D("Nb Conf publique", 
			 "Conference publique", 
			 "nb conf", 
			 dataset7, 
			 PlotOrientation.HORIZONTAL, 
			 true, 
			 true, 
			 false);
	 
//	 chart9 = ChartFactory.createBarChart3D("Etat Serveur - BDD", 
//			 "OK", 
//			 "NOK", 
//			 dataset8, 
//			 PlotOrientation.HORIZONTAL, 
//			 true, 
//			 true, 
//			 false);
	 
	 
	  //Create this panel

	 
	 this.setLayout( new GridLayout( 2, 2 ) );
	 this.panel1 = new ChartPanel( chart1 );
	 this.panel2 = new ChartPanel( chart2 );
	 this.panel3 = new ChartPanel( chart3 );
	 this.panel4 = new ChartPanel( chart4 );
//	 this.panel5 = new ChartPanel( chart5 );
	 this.panel6 = new ChartPanel( chart6 );
	 this.panel7 = new ChartPanel( chart7 );
	 this.panel8 = new ChartPanel( chart8 );
	 
	
	 
	 JButton AcutaliserInfomonitoring = new JButton("Actualiser les informations");
	 this.panel9= AcutaliserInfomonitoring;
	 AcutaliserInfomonitoring.addActionListener(new Control(this, eConf));

	 this.add( panel1 );
	 this.add( panel2 );
	 this.add( panel3 );
	 this.add( panel4 );
//	 this.add( panel5 );
	 this.add( panel6 );
	 this.add( panel7 );
	 this.add( panel8 );
	 this.add( panel9 );							
	}
	 
	 public static void main( String[] args )
	 {

		 
//	  JFrame frame = new JFrame( "Supervision eConf" );
//	  afficheBodyGraphSupervision chart = new afficheBodyGraphSupervision();
//	  frame.getContentPane().add( chart, BorderLayout.CENTER );
//	  frame.setSize( 1340, 660 );
//	  frame.setVisible( true );
//	  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	  
	 }
}
